﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerFrame
{
    /// <summary>
    /// 缓存客户端的池子
    /// </summary>
    public class UserTokenCache
    {
        Stack<UserToken> cache;

        public UserTokenCache()
        {
            cache = new Stack<UserToken>();
        }

        public UserTokenCache(int initCount)
        {
            cache = new Stack<UserToken>();
            for (int i = 0; i < initCount; i++)
            {
                cache.Push(new UserToken());
            }
        }

        public void Push(UserToken token)
        {
            if (token != null)
            {
                cache.Push(token);
            }
        }

        public UserToken Pop()
        {
            if (cache.Count == 0)
            {
                return new UserToken();
            }
            return cache.Pop();
        }

        public int Size
        {
            get { return cache.Count; }
        }
    }
}
